<template>
  <div class="main">
    <!-- 顶部轮播 -->
    <swiper :options="swiperOption">
      <swiper-slide v-for="(item, index) in bannerData" :key="index">
        <a target="_blank" :href="item.url">
          <img :src="item.image" alt="" srcset="" />
        </a>
      </swiper-slide>
    </swiper>
    <div class="center">
      <div class="lf">
        <!-- 左侧文章 -->
        <div class="head">{{ newsDetailData.title }}</div>
        <div class="body" v-html="newsDetailData.content"></div>
      </div>
      <div class="rt">
        <!-- 右侧部分 -->
        <router-link v-for="(item,index) in newestNewsData.slice(0,1)" :key="index" class="top" :to="{ name: 'newsDetail', query: { id: item.id } }">
          <el-image
            lazy
            :src="item.image"
            alt=""
          />
          <p>{{item.title}}</p>
        </router-link>
        <!-- 最新资讯 -->
        <div class="new">
          <div class="head">最新资讯</div>
          <div class="body">
            <div class="img-wrap">
              <router-link
                class="img"
                v-for="(item, index) in newestNewsData.slice(0, 2)"
                :key="index"
                :to="{ name: 'newsDetail', query: { id: item.id } }"
              >
                <el-image lazy :src="item.image" alt="" />
              </router-link>
            </div>
            <router-link
              :to="{ name: 'newsDetail', query: { id: item.id } }"
              v-for="(item, index) in newestNewsData.slice(0, 10)"
              :key="index"
            >
              <span>{{ index + 1 }}</span>
              {{ item.title }}
            </router-link>
          </div>
        </div>
        <!-- 明星/作品 -->
        <!-- <div class="recommend">
          <div class="head">明星/作品</div>
          <div class="body">
            <router-link
              class="item"
              :to="{ name: 'newsDetail', query: { id: 1 } }"
              v-for="(item, index) in 2"
              :key="index"
            >
              <el-image
                lazy
                src="http://placehold.it/80x120&text=80x120"
                alt=""
              />
              <dl>
                <dt>林更新</dt>
                <dd>
                  《步步惊心》《步步惊心》《步步惊心》
                  《轩辕剑之天之痕》《轩辕剑之天之痕》 《轩辕剑之天之痕》...
                </dd>
              </dl>
            </router-link>
          </div>
        </div> -->
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      // 顶部轮播图设置
      swiperOption: {
        autoplay: {
          disableOnInteraction: false, // 用户操作swiper之后，是否禁止autoplay
          delay: 5000, // 自动切换的时间间隔（单位ms）
        },
        // loop: true,
      },
      bannerData: [],
      newsDetailData: [],
      newestNewsData:[]
    };
  },
  created() {
    const id = this.$route.query.id;
    // 顶部轮播
    this.$http.getBanner().then((res) => {
      if (res.data.code === 0) {
        this.bannerData = res.data.data;
      } else {
        this.$message.error("获取失败，请重试！");
      }
    });
    this.$http.getNewsDetail(id).then((res) => {
      if (res.data.code === 0) {
        this.newsDetailData = res.data.data;
        // console.log(res.data);
      } else {
        this.$message.error("获取失败，请重试！");
      }
    });
    // 最新资讯
    this.$http.getNews().then((res) => {
      if (res.data.code === 0) {
        if (res.data.data.length <= 0) {
          this.$message.error("没有更多数据！");
          this.page = 1;
          return;
        }
        this.newestNewsData = res.data.data;
      } else {
        this.$message.error("获取失败，请重试！");
      }
    });
  },
};
</script>

<style lang="scss" scoped>
::v-deep {
  .swiper-container {
    height: 400px;
    width: 100%;
    img {
      width: 100%;
      height: 100%;
    }
  }
}
.center {
  width: 1600px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  .lf {
    width: 1094px;
    margin-top: 30px;
    .head {
      font-size: 20px;
      font-family: PingFang SC;
      font-weight: bold;
      line-height: 40px;
      color: #333333;
    }
    .body {
      font-size: 16px;
      font-family: PingFang SC;
      font-weight: 400;
      line-height: 26px;
      color: #333333;
      padding-top: 20px;
      padding-bottom: 40px;
    }
  }
  .rt {
    width: 376px;
    margin-top: 70px;
    .top {
      display: block;
      width: 376px;
      height: 310px;
      position: relative;
      .el-image {
        width: 376px;
        height: 310px;
      }
      p {
        font-size: 20px;
        font-family: PingFang SC;
        font-weight: 400;
        width: 100%;
        height: 66px;
        line-height: 66px;
        background: linear-gradient(
          180deg,
          rgba(0, 0, 0, 0.4) 0%,
          #000000 100%
        );
        color: #ffffff;
        text-align: center;
        position: absolute;
        bottom: 0;
        left: 0;
      }
    }
    .new {
      .head {
        font-size: 20px;
        font-family: PingFang SC;
        font-weight: bold;
        line-height: 40px;
        color: #333333;
        margin-top: 40px;
      }
      .body {
        .img-wrap {
          display: flex;
          justify-content: space-between;
          margin: 20px 0;
          a {
            display: block;
            width: 180px;
            height: 180px;
            .el-image {
              width: 180px;
              height: 180px;
            }
          }
        }
        a {
          display: inline-block;
          font-size: 20px;
          font-family: PingFang SC;
          font-weight: 400;
          line-height: 30px;
          color: #333333;
          width: 376px;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
          span {
            display: inline-block;
            width: 30px;
            font-size: 16px;
            font-weight: bold;
            text-align: center;
          }
        }
        a:hover {
          text-decoration: underline;
        }
      }
    }
    .recommend {
      .head {
        font-size: 20px;
        font-family: PingFang SC;
        font-weight: bold;
        line-height: 40px;
        color: #333333;
        margin-top: 80px;
      }
      .body {
        margin-top: 20px;
        .item {
          display: flex;
          justify-content: space-between;
          .el-image {
            width: 80px;
            height: 120px;
          }
          dl {
            width: 288px;
            dt {
              font-size: 20px;
              font-family: PingFang SC;
              font-weight: bold;
              line-height: 40px;
              color: #333333;
              overflow: hidden;
              text-overflow: ellipsis;
              white-space: nowrap;
            }
            dd {
              margin-top: 10px;
              font-size: 16px;
              font-family: PingFang SC;
              font-weight: 400;
              line-height: 24px;
              color: #333333;
              display: -webkit-box;
              -webkit-box-orient: vertical;
              -webkit-line-clamp: 3;
              overflow: hidden;
            }
          }
        }
        .item:not(:first-child) {
          margin-top: 20px;
        }
      }
    }
  }
}
</style>